window.onload = function(){
	//轮播图部分
	var pic = document.getElementsByClassName("lunbo")[0];
	var list = document.getElementsByClassName("goods")[0];
	var btnList = document.getElementsByClassName("fenlei")[0];
	var btn = btnList.getElementsByTagName("li");
	var timer = null;
	var a = 0;
	function lb(){
		a -= 100;
		a = a < -400 ? 0:a;
		pic.style.left = a+"%";
	}
	timer = setInterval(lb,4000);
	//获取商品
	function getData(a){
		ajax("goods.json",function(mag){
			var data = JSON.parse(mag);
			var str = "";
			var datas = data.data;
			for(var i in datas){
				if((datas[i].goodsId%3)==a){
					str += '<dl><dt class="l"><img src="img/'+datas[i].pic+'"/></dt><dd class="l"><p class="goodsName">'+datas[i].goodsName+'【<span class="add">'+datas[i].address+'</span>】</p><p class="fanli"><i>返</i><span class="fl">1.00</span>元</p><p class="num">没人每期限定返3份</p></dd></dl>'	
				}else if(a==4){
					str += '<dl><dt class="l"><img src="img/'+datas[i].pic+'"/></dt><dd class="l"><p class="goodsName">'+datas[i].goodsName+'【<span class="add">'+datas[i].address+'</span>】</p><p class="fanli"><i>返</i><span class="fl">1.00</span>元</p><p class="num">没人每期限定返3份</p></dd></dl>'
				}
			}
			list.innerHTML = str;
		},function(){
		
		})
	}
	getData(4);
	//点击
	for(var j=0; j < btn.length;j++){
		btn[j].onclick = (function(index){
			return function(){
				for(var m in btn){
					btn[m].className = "";
				}
				btn[index].className = "cur";
				var b = btn[index].getAttribute("dataid");
				getData(b);	
			}	
		})(j)	
	}
	
};

